// pages/liveTotalComment/liveTotalComment.js
const app = getApp();
var utils = require("../../utils/utils.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    childComment: "",
    childExceptionCollect: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      activityChildId: options.activityChildId
    })
    this.queryChildInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  queryChildInfo: function() {
    let that = this
    // 首页头部地区接口
    wx.request({
      url: app.httpUrl + '/activity/queryChildInfo',
      header: {
        'xcx-xtoken': app.globalData.openid,
        'content-type': 'application/json' // 默认值
      },
      method: "POST",
      data: {
        activityChildId: this.data.activityChildId
      },
      success: res => {
        if(res.data.code == '000') {
          that.setData({
            childComment: res.data.data.childComment,
            childExceptionCollect: res.data.data.childExceptionCollect
          })
        }
      }
    })
  },
  submitTab: function() {
    var that = this;
    var childComment = that.data.childComment;
    var childExceptionCollect = that.data.childExceptionCollect;
    if (childComment.length == 0 && childExceptionCollect.length == 0) {
      return;
    }
    wx.request({
      url: app.httpUrl + '/activity/tutor/addChildTotalComment',
      header: {
        'xcx-xtoken': app.globalData.openid,
        'content-type': 'application/json' // 默认值
      },
      method: "POST",
      data: {
        id: this.data.activityChildId,
        childComment: childComment,
        childExceptionCollect: childExceptionCollect
      },
      success: res => {
        if (res.data.code == '000') {
          wx.showToast({ title: '提交成功！', icon: 'success', duration: 3000 });
          return;
        }
        wx.showToast({ title: res.data.msg, icon: 'none', duration: 3000 });
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
  childCommentInputs: function (e) {
    // 获取输入框的内容
    var value = e.detail.value;
    this.setData({
      childComment: value
    })
  },
  //字数限制  
  childExceptionCollectInputs: function (e) {
    // 获取输入框的内容
    var value = e.detail.value;
    this.setData({
      childExceptionCollect: value
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})